home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / update-inetd < prev    next >
Encoding:
Text File  |  2011-09-18  |  6.0 KB  |  173 lines

  1. #!/usr/bin/perl
  2. #
  3. # update-inetd: a utility to add entries to the /etc/inetd.conf file
  4. #
  5. # Copyright (C) 1995 Peter Tobias <tobias@et-inf.fho-emden.de>
  6. #
  7. #    update-inetd is free software; you can redistribute it and/or modify
  8. #    it under the terms of the GNU General Public License as published
  9. #    by the Free Software Foundation; either version 2 of the License,
  10. #    or (at your option) any later version.
  11. #
  12. #    update-inetd is distributed in the hope that it will be useful, but
  13. #    WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. #    General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with update-inetd; if not, write to the Free Software Foundation,
  19. #    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21.  
  22. require 5.000;
  23. require DebianNet;
  24.  
  25. $| = 1;
  26.  
  27. $version = "1.12";
  28.  
  29. $0 =~ s#.*/##;
  30.  
  31. while ($ARGV[0] =~ m/^-/) {
  32.     $_ = shift(@ARGV);
  33.     if (/--help$/) {
  34.         &usage;
  35.     } elsif (/--version$/) {
  36.         &version;
  37.     } elsif (/--add$/) {
  38.         $mode="add";
  39.     } elsif (/--remove$/) {
  40.         $mode="remove";
  41.     } elsif (/--enable$/) {
  42.         $mode="enable";
  43.     } elsif (/--disable$/) {
  44.         $mode="disable";
  45.     } elsif (/--multi$/) {
  46.         $DebianNet::multi = "true";
  47.     } elsif (/--verbose$/) {
  48.         $DebianNet::verbose = "true";
  49.     } elsif (/--debug$/) {
  50.         $debug = "true";
  51.     } elsif (/--file$/) {
  52.         $file = shift(@ARGV);
  53.         die "$0: Option \`--file' requires an argument\n" unless ($file and not ($file =~ m/^--/));
  54.         $DebianNet::inetdcf = $file;
  55.     } elsif (/--group$/) {
  56.         $group = shift(@ARGV);
  57.         die "$0: Option \`--group' requires an argument\n" unless ($group and not ($group =~ m/^--/));
  58.     } elsif (/--comment-chars$/) {
  59.         $sep = shift(@ARGV);
  60.         die "$0: Option \`--comment-chars' requires an argument\n" unless ($sep);
  61.         die "$0: The comment characters do not start with a \`#'!\n" unless ($sep =~ /^#/);
  62.         $DebianNet::sep = $sep;
  63.     } elsif (/--pattern$/) {
  64.         $pattern = shift(@ARGV);
  65.         die "$0: Option \`--pattern' requires an argument\n" unless ($pattern and not ($pattern =~ m/^--/));
  66.     } else {
  67.         print STDERR "$0: Unknown option: $_\n";
  68.         print STDERR "Try \`$0 --help' for more information.\n";
  69.         exit(1);
  70.     }
  71. }
  72.  
  73. $group = "OTHER" unless ($group);
  74.  
  75. &usage unless($mode);
  76.  
  77. # die "You must be root to run this script.\n" if ($> != 0);
  78.  
  79. if ($#ARGV > 0) {
  80.     print STDERR "Too many arguments!\n";
  81. } elsif ($#ARGV == -1) {
  82.     print STDERR "Too few arguments!\n";
  83. } else {
  84.     $modearg = $ARGV[0];
  85.     die "The service name may not include a whitespace character!\n" if (($mode eq "enable" or $mode eq "disable") and ($modearg =~ /\s+|\\t/));
  86.     die "The entry definition does not contain any whitespace characters!\n" if ($mode eq "add" and not ($modearg =~ /\s+|\\t/));
  87. }
  88.  
  89. print STDERR "Processing $DebianNet::inetdcf\n" if (defined($DebianNet::verbose));
  90. print STDERR "Using mode \"$mode\", group \"$group\", pattern \"$pattern\" and seperator \"$DebianNet::sep\"\n" if (defined($debug));
  91. print STDERR "Multiple remove/disable: $DebianNet::multi\n" if (defined($debug) and defined($DebianNet::multi));
  92. print STDERR "ARGUMENT: $modearg\n" if (defined($debug));
  93.  
  94. my $xinetd = 0;
  95. if (( -f "/etc/xinetd.conf" ) && ( -x "/usr/sbin/xinetd" )
  96.     && (!defined($ENV{"UPDATE_INETD_NOXINETD"}))) {
  97.     $xinetd = 1;
  98. }
  99.  
  100. if ($mode eq "add") {
  101.     if ($xinetd) {
  102.         print STDERR "Note: xinetd currently is not fully supported by update-inetd.\n";
  103.         print STDERR "      Please consult /usr/share/doc/xinetd/README.Debian and itox(8).\n";
  104.     }
  105.  
  106.     DebianNet::add_service($modearg, $group);
  107. } elsif ($mode eq "remove") {
  108.     DebianNet::remove_service($modearg);
  109. } elsif ($mode eq "enable") {
  110.     @arglst = split(/,/, $modearg);
  111.     while(@arglst) {
  112.         $_ = shift(@arglst);
  113.         DebianNet::enable_service($_, $pattern);
  114.     }
  115. } elsif ($mode eq "disable") {
  116.     @arglst = split(/,/, $modearg);
  117.     while(@arglst) {
  118.         $_ = shift(@arglst);
  119.         DebianNet::disable_service($_, $pattern);
  120.     }
  121. } else {
  122.     die "Mode = \`$modearg'? This should not happen!\n";
  123. }
  124.  
  125. # in case of xinetd, we have no clue about whether to
  126. # restart/SIGHUP/noop so we always restart anyway
  127. if ($xinetd && !$DebianNet::called_wakeup_inetd) {
  128.     DebianNet::wakeup_inetd(0);
  129. }
  130.  
  131. sub version {
  132.     print STDERR "$0 $version\n";
  133.     print STDERR "DebianNet module $DebianNet::version\n";
  134.     exit(0);
  135. }
  136.  
  137. sub usage {
  138.     print STDERR <<EOF;
  139. Usage: $0 [OPTION] MODE ARGUMENT
  140.  
  141. Options:
  142.   --version                       output version information and exit
  143.   --help                          display this help and exit
  144.   --verbose                       explain what is being done
  145.   --debug                         enables debugging mode
  146.   --multi                         allow multiple removes/disables
  147.   --file FILENAME                 use FILENAME instead of /etc/inetd.conf
  148.   --group GROUPNAME               add entry to section GROUPNAME
  149.   --comment-chars CHARACTERS      use CHARACTERS as comment characters
  150.   --pattern PATTERN               use PATTERN to select a service
  151.  
  152. Modes:
  153.   --add ENTRY                     add ENTRY to $DebianNet::inetdcf
  154.   --remove ENTRY                  remove ENTRY (regular expression)
  155.   --enable SERVICE                enable SERVICE in $DebianNet::inetdcf
  156.   --disable SERVICE               disable SERVICE in $DebianNet::inetdcf
  157.  
  158. In order to prevent the shell from changing your ENTRY definition
  159. you have to quote the ENTRY using single or double quotes. You can
  160. use tabs (the tab character or \\t) and spaces to separate the fields
  161. of the ENTRY. If you want to enable/disable more than one SERVICE you
  162. can use a comma separated list of services (no whitespace characters
  163. allowed).
  164.  
  165. Note: users must use --comment-chars '#' to disable a service for that setting
  166. to survive upgrades. Package maintainer scripts should use the default
  167. --comment-chars. See update-inetd(8) for details.
  168.  
  169. EOF
  170.     exit(0);
  171. }
  172.  
  173.